package com.znyj.servlet.dao;

import com.znyj.servlet.entity.TaskEntity;
import com.znyj.servlet.sqlHelper.SqlProvider;
import com.znyj.servlet.sqlHelper.SqlRequest;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by gaoliwei02 on 17/6/5.
 */
@Repository
public interface TaskDao {

    public static final String SIMPLE_SELECT_KEYS = "id,device_id";

    @Select(" select " + SIMPLE_SELECT_KEYS + " from cdb_task where device_id=#{deviceId}")
    public TaskEntity findByDeviceId(@Param("deviceId") String deviceId);

    @Select("select order_id from cdb_task order by id desc limit 1")
    public long findNewestOrderId();

    @Select("select * from cdb_task where order_id=#{orderId}")
    public TaskEntity findByOrderId(@Param("orderId") Long orderId);

    @Select("select * from cdb_task where device_id=#{deviceId} order by id desc limit 1")
    public TaskEntity findNewestDeviceId(@Param("deviceId") String deviceId);

    @SelectProvider(type = SqlProvider.class, method = "findLast")
    public TaskEntity findLast(String deviceId);

    @SelectProvider(type = SqlProvider.class, method = "query")
    public List<TaskEntity> query(SqlRequest request);

    @SelectProvider(type = SqlProvider.class, method = "count")
    public int count(SqlRequest request);
}
